关于MySql链接url参数的设置 专题
报错:
Establishing SSL connection without server's identity verification is not recommended.
According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set.
For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'.
You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
解决办法:
在jdbc.url上添加配置:
useSSL=true
eg:
jdbc.url=jdbc:mysql://localhost:3306/dbName?useUnicode=true&useSSL=true
一个在用的配置:
?useUnicode=true&useSSL=true&autoReconnect=true&failOverReadOnly=false
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=TRUE
jdbc.username=root
jdbc.password=password
database.url=jdbc:mysql://database_server:3306/oauth?autoReconnect=true&useUnicode=true&createDatabaseIfNotExist=true&characterEncoding=utf8&useSSL=true&serverTimezone=UTC
特别说明其中的jdbc.url配置:如果你已经升级好了mysql-connector,其中的characterEncoding=utf8可以被自动被识别为utf8mb4(当然也兼容原来的utf8),而autoReconnect配置我强烈建议配上,我之前就是忽略了这个属性,导致因为缓存缘故,没有读取到DB最新配置,导致一直无法使用utf8mb4字符集,多么痛的领悟!!
没有让mysql驱动开启批量执行sql的开关。
怎么开启呢?在拼装mysql链接的url时,为其加上allowMultiQueries参数,设置为true,如下:
jdbc.jdbcUrl=jdbc:mysql://127.0.0.1:3306/database?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
mysql JDBC URL格式如下:
jdbc:mysql://[host:port],[host:port].../[database][?参数名1][=参数值1][&参数名2][=参数值2]...
常用的几个较为重要的参数:
参数名称 参数说明 缺省值 最低版本要求
user 数据库用户名(用于连接数据库) 所有版本
passWord 用户密码(用于连接数据库) 所有版本
useUnicode 是否使用Unicode字符集,如果参数characterEncoding设置为gb2312或gbk,本参数值必须设置为true false 1.1g
characterEncoding 当useUnicode设置为true时,指定字符编码。比如可设置为gb2312或gbk false 1.1g
autoReconnect 当数据库连接异常中断时,是否自动重新连接? false 1.1
autoReconnectForPools 是否使用针对数据库连接池的重连策略 false 3.1.3
failOverReadOnly 自动重连成功后,连接是否设置为只读? true 3.0.12
maxReconnects autoReconnect设置为true时,重试连接的次数 3 1.1
initialTimeout autoReconnect 设置为true时,两次重连之间的时间间隔,单位:秒 2 1.1
connectTimeout 和数据库服务器建立socket连接时的超时,单位:毫秒。 0表示永不超时,适用于JDK 1.4及更高版本 0 3.0.1
socketTimeout socket操作(读写)超时,单位:毫秒。 0表示永不超时 0 3.0.1
failOverReadOnly是MySQL JDBC驱动程序提供的一个连接选项,用于指定在自动重连时是否使用只读模式连接到MySQL服务器。当使用autoReconnect选项时,如果连接断开,则驱动程序会自动尝试重新连接到MySQL服务器,并根据failOverReadOnly选项确定连接模式。
同时,在MySQL 8.0版本之后,autoReconnect、maxReconnects和failOverReadOnly选项已经被移除,官方建议使用更加稳定和可靠的应用程序级别的重新连接策略。
maxReconnects是MySQL JDBC驱动程序提供的一个连接选项,用于指定自动重连时最大尝试次数。当使用autoReconnect选项时,如果连接断开,则驱动程序会自动尝试重新连接到MySQL服务器,直到达到最大尝试次数为止。
在JDBC URL中设置maxReconnects选项即可指定最大尝试次数。
需要注意的是,autoReconnect
和maxReconnects
选项存在一些限制和潜在问题,可能会导致一些不可预知的行为。因此,建议仅在必要时才使用这些选项,并谨慎评估其风险和影响。
同时,在MySQL 8.0版本之后,autoReconnect
和maxReconnects
选项已经被移除,官方建议使用更加稳定和可靠的应用程序级别的重新连接策略。
autoReconnect
是MySQL JDBC驱动程序提供的一个连接选项,用于自动重新连接到MySQL服务器。当MySQL服务器断开连接时(如网络中断、服务器关闭等情况),该选项可以在下一次尝试使用连接时自动重新建立连接。
在JDBC URL中设置autoReconnect
选项为true即可启用该功能。
同时,在MySQL 8.0版本之后,该选项已经被移除,官方建议使用更加稳定和可靠的应用程序级别的重新连接策略。
zeroDateTimeBehavior是MySQL JDBC驱动程序提供的一个连接选项,用于指定在将零时间值(即0000-00-00 00:00:00)转换为Java日期类型时的行为。在默认情况下,MySQL JDBC驱动程序会将零时间值转换为null值,但可以通过设置zeroDateTimeBehavior选项来更改此行为。
在JDBC URL中设置zeroDateTimeBehavior选项即可指定转换行为。以下是一些常用的选项:
convertToNull:将零时间值转换为null值。
round:将零时间值转换为Java Date对象的最小值(即1970年1月1日)。
exception:将零时间值抛出SQLException异常。
例如:
jdbc:mysql://localhost:3306/test?autoReconnect=true&maxReconnects=3&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull
上述示例中,设置了zeroDateTimeBehavior选项为convertToNull,表示将零时间值转换为null值。
需要注意的是,zeroDateTimeBehavior选项存在一些限制和潜在问题,可能会导致一些不可预知的行为。因此,建议仅在必要时才使用该选项,并谨慎评估其风险和影响。
同时,在MySQL 8.0版本之后,zeroDateTimeBehavior选项已经被移除,官方建议使用更加稳定和可靠的应用程序级别的零时间值处理策略。
总之,zeroDateTimeBehavior是MySQL JDBC驱动程序提供的一个连接选项,用于指定将零时间值转换为Java日期类型时的行为。建议仅在必要时使用该选项,并谨慎评估其风险和影响。
<dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>8.0.33</version> <exclusions> <exclusion> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> </exclusion> </exclusions> </dependency>
2023-06-08 11:05:29.601 DEBUG 22938 --- [ main] c.z.g.v.a.d.c.r.m.G.selectPage : ==> Preparing: SELECT invoice_info_id,latest_order_time FROM user_order WHERE (invoice_info_id = ?) LIMIT ? 2023-06-08 11:05:29.610 DEBUG 22938 --- [ main] c.z.g.v.a.d.c.r.m.G.selectPage : ==> Parameters: 80(Integer), 3(Long) org.springframework.dao.TransientDataAccessResourceException: Error attempting to get column 'latest_order_time' from result set. Cause: java.sql.SQLException: Zero date value prohibited ; Zero date value prohibited; nested exception is java.sql.SQLException: Zero date value prohibited at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:110) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79) at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:91) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441) at com.sun.proxy.$Proxy106.selectList(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForIPage(MybatisMapperMethod.java:121) at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:85) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) at com.sun.proxy.$Proxy112.selectPage(Unknown Source) at com.view.adapter.db.customer.repository.InvoiceRepository.selectPage(InvoiceRepository.java:32) at com.view.adapter.db.customer.repository.InvoiceRepository$$FastClassBySpringCGLIB$$90f1fa17.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) at com.view.adapter.db.customer.repository.InvoiceRepository$$EnhancerBySpringCGLIB$$dcee9a9e.selectPage(<generated>) at com.view.adapter.db.customer.repository.InvoiceRepositoryTest.selectPage(InvoiceRepositoryTest.java:31) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725) at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131) at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84) at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115) at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at java.util.ArrayList.forEach(ArrayList.java:1259) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at java.util.ArrayList.forEach(ArrayList.java:1259) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86) at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86) at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) Caused by: java.sql.SQLException: Zero date value prohibited at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:130) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:98) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:90) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:64) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:74) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:99) at com.mysql.cj.jdbc.result.ResultSetImpl.getTimestamp(ResultSetImpl.java:947) at com.mysql.cj.jdbc.result.ResultSetImpl.getTimestamp(ResultSetImpl.java:985) at com.alibaba.druid.filter.FilterChainImpl.resultSet_getTimestamp(FilterChainImpl.java:1219) at com.alibaba.druid.filter.FilterAdapter.resultSet_getTimestamp(FilterAdapter.java:1826) at com.alibaba.druid.filter.FilterChainImpl.resultSet_getTimestamp(FilterChainImpl.java:1215) at com.alibaba.druid.filter.FilterAdapter.resultSet_getTimestamp(FilterAdapter.java:1826) at com.alibaba.druid.filter.FilterChainImpl.resultSet_getTimestamp(FilterChainImpl.java:1215) at com.alibaba.druid.filter.FilterAdapter.resultSet_getTimestamp(FilterAdapter.java:1826) at com.alibaba.druid.filter.FilterChainImpl.resultSet_getTimestamp(FilterChainImpl.java:1215) at com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl.getTimestamp(ResultSetProxyImpl.java:725) at com.alibaba.druid.pool.DruidPooledResultSet.getTimestamp(DruidPooledResultSet.java:353) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:69) at com.sun.proxy.$Proxy158.getTimestamp(Unknown Source) at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:39) at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:28) at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:85) at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyAutomaticMappings(DefaultResultSetHandler.java:561) at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:403) at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:355) at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:329) at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:302) at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:195) at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65) at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:64) at com.sun.proxy.$Proxy155.query(Unknown Source) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:81) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) at com.sun.proxy.$Proxy154.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ... 88 more Caused by: com.mysql.cj.exceptions.DataReadException: Zero date value prohibited at com.mysql.cj.result.SqlTimestampValueFactory.localCreateFromDatetime(SqlTimestampValueFactory.java:173) at com.mysql.cj.result.SqlTimestampValueFactory.localCreateFromDatetime(SqlTimestampValueFactory.java:51) at com.mysql.cj.result.AbstractDateTimeValueFactory.createFromDatetime(AbstractDateTimeValueFactory.java:104) at com.mysql.cj.protocol.a.MysqlTextValueDecoder.decodeDatetime(MysqlTextValueDecoder.java:90) at com.mysql.cj.protocol.result.AbstractResultsetRow.decodeAndCreateReturnValue(AbstractResultsetRow.java:86) at com.mysql.cj.protocol.result.AbstractResultsetRow.getValueFromBytes(AbstractResultsetRow.java:243) at com.mysql.cj.protocol.a.result.ByteArrayRow.getValue(ByteArrayRow.java:91) ... 137 more
解决办法:在jdbc url上添加
driver.url = jdbc:mysql://127.0.0.1:3306/order?useUnicode=true&useSSL=true&autoReconnect=true&failOverReadOnly=false&maxReconnects=30&zeroDateTimeBehavior=convertToNull
https://blog.csdn.net/ywb201314/article/details/51423574
driver.url = jdbc:mysql://127.0.0.1:3306/admin?useUnicode=true&useSSL=true&autoReconnect=true&failOverReadOnly=false&maxReconnects=30
com.alibaba.otter.manager.biz.common.exceptions.ManagerException: com.alibaba.otter.manager.biz.common.exceptions.ManagerException: org.springframework.dao.DataAccessResourceFailureException: SqlMapClient operation; SQL []; --- The error occurred while applying a parameter map. --- Check the listPipelineByIds-InlineParameterMap. --- Check the statement (query failed). --- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 30 times. Giving up.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred while applying a parameter map. --- Check the listPipelineByIds-InlineParameterMap. --- Check the statement (query failed). --- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 30 times. Giving up. at com.alibaba.otter.manager.biz.config.record.impl.LogRecordServiceImpl.modelToDo(LogRecordServiceImpl.java:165) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] at com.alibaba.otter.manager.biz.config.record.impl.LogRecordServiceImpl.create(LogRecordServiceImpl.java:68) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] at com.alibaba.otter.manager.biz.config.record.impl.LogRecordServiceImpl.create(LogRecordServiceImpl.java:45) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] at com.alibaba.otter.manager.biz.monitor.impl.AbstractRuleMonitor.logRecordAlarm(AbstractRuleMonitor.java:107) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] at com.alibaba.otter.manager.biz.monitor.impl.ExceptionRuleMonitor.feed(ExceptionRuleMonitor.java:63) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] at com.alibaba.otter.manager.biz.remote.impl.ArbitrateRemoteServiceImpl.onNodeAlarm(ArbitrateRemoteServiceImpl.java:58) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] at sun.reflect.GeneratedMethodAccessor318.invoke(Unknown Source) ~[na:na] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181] at com.alibaba.otter.shared.communication.core.impl.AbstractCommunicationEndpoint.acceptEvent(AbstractCommunicationEndpoint.java:72) [shared.communication-4.2.18-SNAPSHOT.jar:na] at com.alibaba.dubbo.common.bytecode.Wrapper0.invokeMethod(Wrapper0.java) [na:2.5.3] at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46) [dubbo-2.5.3.jar:2.5.3] at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72) [dubbo-2.5.3.jar:2.5.3] at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:108) [dubbo-2.5.3.jar:2.5.3] at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:84) [dubbo-2.5.3.jar:2.5.3] at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170) [dubbo-2.5.3.jar:2.5.3] at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52) [dubbo-2.5.3.jar:2.5.3] at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:82) [dubbo-2.5.3.jar:2.5.3] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_181] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_181] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181] Caused by: com.alibaba.otter.manager.biz.common.exceptions.ManagerException: org.springframework.dao.DataAccessResourceFailureException: SqlMapClient operation; SQL []; --- The error occurred while applying a parameter map. --- Check the listPipelineByIds-InlineParameterMap. --- Check the statement (query failed). --- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 30 times. Giving up.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred while applying a parameter map. --- Check the listPipelineByIds-InlineParameterMap. --- Check the statement (query failed). --- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 30 times. Giving up. at com.alibaba.otter.manager.biz.config.pipeline.impl.PipelineServiceImpl.listByIds(PipelineServiceImpl.java:356) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] at com.alibaba.otter.manager.biz.config.pipeline.impl.PipelineServiceImpl.findById(PipelineServiceImpl.java:222) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] at com.alibaba.otter.manager.biz.config.pipeline.impl.PipelineServiceImpl.findById(PipelineServiceImpl.java:53) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] at com.alibaba.otter.manager.biz.config.channel.impl.ChannelServiceImpl.findByPipelineId(ChannelServiceImpl.java:280) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] at com.alibaba.otter.manager.biz.config.record.impl.LogRecordServiceImpl.modelToDo(LogRecordServiceImpl.java:145) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] ... 20 common frames omitted Caused by: org.springframework.dao.DataAccessResourceFailureException: SqlMapClient operation; SQL []; --- The error occurred while applying a parameter map. --- Check the listPipelineByIds-InlineParameterMap. --- Check the statement (query failed). --- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 30 times. Giving up.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred while applying a parameter map. --- Check the listPipelineByIds-InlineParameterMap. --- Check the statement (query failed). --- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 30 times. Giving up. at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104) ~[spring-jdbc-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) ~[spring-jdbc-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:203) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:293) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE] at com.alibaba.otter.manager.biz.config.pipeline.dal.ibatis.IbatisPipelineDAO.listByMultiId(IbatisPipelineDAO.java:78) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] at com.alibaba.otter.manager.biz.config.pipeline.impl.PipelineServiceImpl.listByIds(PipelineServiceImpl.java:346) ~[manager.biz-4.2.18-SNAPSHOT.jar:na] ... 24 common frames omitted Caused by: com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred while applying a parameter map. --- Check the listPipelineByIds-InlineParameterMap. --- Check the statement (query failed). --- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 30 times. Giving up. at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201) ~[ibatis-sqlmap-2.3.4.726.jar:na] at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139) ~[ibatis-sqlmap-2.3.4.726.jar:na] at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567) ~[ibatis-sqlmap-2.3.4.726.jar:na] at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541) ~[ibatis-sqlmap-2.3.4.726.jar:na] at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118) ~[ibatis-sqlmap-2.3.4.726.jar:na] at org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:295) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMapClientTemplate.java:1) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE] ... 27 common frames omitted Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 30 times. Giving up. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_181] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_181] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_181] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_181] at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.Util.getInstance(Util.java:408) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2163) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2088) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2533) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192) ~[mysql-connector-java-5.1.40.jar:5.1.40] at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) ~[commons-dbcp-1.4.jar:1.4] at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) ~[commons-dbcp-1.4.jar:1.4] at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185) ~[ibatis-sqlmap-2.3.4.726.jar:na] at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221) ~[ibatis-sqlmap-2.3.4.726.jar:na] at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189) ~[ibatis-sqlmap-2.3.4.726.jar:na] ... 34 common frames omitted Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.GeneratedConstructorAccessor55.newInstance(Unknown Source) ~[na:na] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_181] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_181] at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2251) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2104) ~[mysql-connector-java-5.1.40.jar:5.1.40] ... 43 common frames omitted Caused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_181] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_181] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_181] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_181] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_181] at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_181] at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211) ~[mysql-connector-java-5.1.40.jar:5.1.40] at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300) ~[mysql-connector-java-5.1.40.jar:5.1.40] ... 45 common frames omitted
对应中文环境,通常mysql连接URL可以设置为:
在使用数据库连接池的情况下,最好设置如下两个参数:
autoReconnect=true&failOverReadOnly=false
比如在tomcat的server.xml中配置数据库连接池时,mysql jdbc url样例如下:
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly
http://www.jb51.net/article/47764.htm
备注:mysql5以上的,设置autoReconnect=true 是无效的 只有4.x版本,起作用
jdbc:mysql://127.0.0.1:3306/demo_ds?useServerPrepStmts=true&cachePrepStmts=true
设置参数useServerPrepStmts=true,这个参数的作用是让MySQL服务进行prepare。没有这个参数就是让JDBC进行prepare,MySQL完全感知不到,是没有什么意义的。
cachePrepStmts=true这个参数的意思是告诉JDBC缓存需要prepare的SQL
https://www.cnblogs.com/softidea/p/9180189.html
报错:
Caused by: java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Timestamp at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ~[mysql-connector-java-5.1.42.jar:5.1.42] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897) ~[mysql-connector-java-5.1.42.jar:5.1.42] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886) ~[mysql-connector-java-5.1.42.jar:5.1.42] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) ~[mysql-connector-java-5.1.42.jar:5.1.42] at com.mysql.jdbc.ResultSetRow.getNativeTimestamp(ResultSetRow.java:620) ~[mysql-connector-java-5.1.42.jar:5.1.42] at com.mysql.jdbc.ByteArrayRow.getNativeTimestamp(ByteArrayRow.java:187) ~[mysql-connector-java-5.1.42.jar:5.1.42] at com.mysql.jdbc.ResultSetImpl.getNativeTimestamp(ResultSetImpl.java:4308) ~[mysql-connector-java-5.1.42.jar:5.1.42] at com.mysql.jdbc.ResultSetImpl.getTimestampInternal(ResultSetImpl.java:5904) ~[mysql-connector-java-5.1.42.jar:5.1.42] at com.mysql.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:5588) ~[mysql-connector-java-5.1.42.jar:5.1.42] at com.mysql.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:5617) ~[mysql-connector-java-5.1.42.jar:5.1.42]
解决办法1:
在jdbc.url上添加配置:
zeroDateTimeBehavior=convertToNull
eg:
jdbc.url=jdbc:mysql://localhost:3306/dbName?useUnicode=true&useSSL=true&zeroDateTimeBehavior=convertToNull
原因:
对于值为0000-00-00 00:00:00(默认值)的记录,根据不同的配置,会返回不同的结果:
不配置:默认返回异常
zeroDateTimeBehavior=round 0001-01-01 00:00:00.0
zeroDateTimeBehavior=convertToNull null
解决方法2:
将日期"0000-00-00 00:00:00”改为正常日期即可。
关于"0000-00-00 00:00:00”: 在mysql中"0000-00-00 00:00:00”是作为一个特殊值存在的,但是在Java中, java.sql.Date 会被视为 不合法的值,被JVM认为格式不正确。
查询的结果集中某数据行的日期值为0000-00-00 00:00:00。因MySQL的时间类型datetime范围是1000-01-01 00:00:00 到 9999-12-31 23:59:59,所以报错。
在spring boot 2.1.6.RELEASE 中,如果没有配置&serverTimezone=Asia/Shanghai , 就会一直报错:
019-07-24 19:07:30.903 ERROR 9712 --- [eate-1446291553] com.alibaba.druid.pool.DruidDataSource : create connection SQLException, url: jdbc:mysql://localhost:3306/wxmp?useUnicode=true&characterEncoding=utf-8&useSSL=false, errorCode 0, state 01S00 java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156) ~[druid-1.1.10.jar:1.1.10] at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218) ~[druid-1.1.10.jar:1.1.10] at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) ~[druid-1.1.10.jar:1.1.10] at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1560) ~[druid-1.1.10.jar:1.1.10] at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1623) ~[druid-1.1.10.jar:1.1.10] at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2468) ~[druid-1.1.10.jar:1.1.10] Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. at sun.reflect.GeneratedConstructorAccessor48.newInstance(Unknown Source) ~[na:na] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_191] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_191] at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2243) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2267) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:966) ~[mysql-connector-java-8.0.16.jar:8.0.16] at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825) ~[mysql-connector-java-8.0.16.jar:8.0.16] ... 9 common frames omitted Disconnected from the target VM, address: '127.0.0.1:57625', transport: 'socket' 2019-07-24 19:07:31.324 INFO 9712 --- [ Thread-15] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor' 2019-07-24 19:07:31.332 INFO 9712 --- [ Thread-15] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.alibaba.druid.pool.DataSourceDisableException ### The error may exist in file [D:\project\work\smartwx-boot\target\classes\mapper\AccountMapper.xml] ### The error may involve com.wxmp.wxcms.mapper.AccountDao.listForPage ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.alibaba.druid.pool.DataSourceDisableException at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
高版本mysql的另外一个坑:
在将库中的下列日期转换成java.util.Date类型时报错:
2020-03-06 08:32:07
2020-03-06 08:32:07
2020-03-06 08:32:07
2020-03-06 08:32:07
2020-03-06 08:32:08
2020-03-06 08:32:08
2020-03-06 08:32:09
2020-03-06 08:32:09
2020-03-06 08:32:10
2020-03-06 08:32:11
2020-03-06 08:32:12
2020-03-06 08:32:12
2020-03-06 08:32:13
2020-03-06 08:33:07
2020-03-06 08:33:07
2020-03-06 08:33:08
2020-03-06 08:33:09
2020-03-06 08:33:09
2020-03-06 08:33:10
2020-03-06 08:33:10
2020-03-06 08:33:11
2020-03-06 08:33:11
2020-03-06 08:33:11
2020-03-06 08:33:12
2020-03-06 08:33:13
2020-03-06 08:33:13
2020-03-06 08:33:36
2020-03-06 08:34:07
2020-03-06 08:34:08
2020-03-06 08:34:08
2020-03-06 08:34:09
2020-03-06 08:34:09
2020-03-06 08:34:10
2020-03-06 08:34:11
2020-03-06 08:34:19
2020-03-06 08:34:20
2020-03-06 08:34:21
2020-03-06 08:34:22
2020-03-06 08:34:22
2020-03-06 08:34:24
2020-03-06 08:35:17
2020-03-06 08:35:18
2020-03-06 08:35:18
2020-03-06 08:35:19
2020-03-06 08:35:20
2020-03-06 08:35:22
2020-03-06 08:35:23
2020-03-06 08:36:07
2020-03-06 08:36:17
2020-03-06 08:36:18
2020-03-06 08:36:18
2020-03-06 08:36:19
2020-03-06 08:36:20
2020-03-06 08:36:20
2020-03-06 08:36:21
2020-03-06 08:36:21
2020-03-06 08:37:07
2020-03-06 08:38:07
2020-03-06 08:38:08
2020-03-06 08:39:17
2020-03-06 08:40:08
2020-03-06 08:40:08
2020-03-06 08:40:09
2020-03-06 08:40:09
2020-03-06 08:40:17
2020-03-06 08:40:20
2020-03-06 08:40:37
2020-03-06 08:41:19
2020-03-06 08:42:05
2020-03-06 08:42:07
2020-03-06 08:42:08
2020-03-06 08:42:08
2020-03-06 08:42:18
2020-03-06 08:44:08
2020-03-06 08:44:28
2020-03-06 08:45:08
2020-03-06 08:45:48
2020-03-06 08:46:39
2020-03-06 08:47:08
2020-03-06 08:47:08
2020-03-06 08:47:48
2020-03-06 08:47:48
2020-03-06 08:48:28
2020-03-06 08:48:28
2020-03-06 08:48:29
2020-03-06 08:49:08
2020-03-06 08:49:09
2020-03-06 08:49:10
2020-03-06 08:49:10
2020-03-06 08:49:11
2020-03-06 08:49:48
2020-03-06 08:50:08
2020-03-06 08:50:09
2020-03-06 08:50:09
2020-03-06 08:50:11
2020-03-06 08:51:08
2020-03-06 08:51:08
2020-03-06 08:51:09
2020-03-06 08:51:18
异常原因
系统时区原因。
解决办法
在数据库连接串加上 &serverTimezone=Asia/Shanghai 即可~
conn_str="jdbc:mysql://${hostname}/${db_name}?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false&serverTimezone=Asia/Shanghai&useSSL=true&dontTrackOpenResources=true&defaultFetchSize=10000&useCursorFetch=true"
其它解决办法:
8.X的版本,DBtime写 :2020-03-08 02:01:43
就会报错。
环境:服务器,mysql都是东八区。使用的springboot2.X,DB中字段类型是timestamp
解决办法:
1. mysql-connector-java.jar版本6.x、8.x降级为5.1.x
2. 对于高版本jdbc,连接串强制指定时区参数:serverTimezone=GMT%2B8
3. 对于高版本jdbc,mysql数据库强制修改time_zone为“+8:00”,而非“SYSTEM
ssl的报错:
[2020-10-12 10:36:23]10.0.12.164 content: Caused by: org.apache.ibatis.exceptions.PersistenceException: [2020-10-12 10:36:23]10.0.12.164 content: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60000, active 0, maxActive 20, creating 1, createElapseMillis 1360, createErrorCount 3737 [2020-10-12 10:36:23]10.0.12.164 content: ### The error may exist in class path resource [mapper/customer/CustomerSalesForceDOMapper.xml] [2020-10-12 10:36:23]10.0.12.164 content: ### The error may involve com.boss.sync.customer.dao.mapper.CustomerSalesForceDOMapper.listCustomerBy [2020-10-12 10:36:23]10.0.12.164 content: ### The error occurred while executing a query [2020-10-12 10:36:23]10.0.12.164 content: ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60000, active 0, maxActive 20, creating 1, createElapseMillis 1360, createErrorCount 3737 [2020-10-12 10:36:23]10.0.12.164 content: at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[mybatis-3.5.4.jar!/:3.5.4] [2020-10-12 10:36:23]10.0.12.164 content: at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149) ~[mybatis-3.5.4.jar!/:3.5.4] [2020-10-12 10:36:23]10.0.12.164 content: at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ~[mybatis-3.5.4.jar!/:3.5.4] [2020-10-12 10:36:23]10.0.12.164 content: at sun.reflect.GeneratedMethodAccessor103.invoke(Unknown Source) ~[na:na] [2020-10-12 10:36:23]10.0.12.164 content: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144] [2020-10-12 10:36:23]10.0.12.164 content: at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144] [2020-10-12 10:36:23]10.0.12.164 content: at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426) ~[mybatis-spring-2.0.4.jar!/:2.0.4] [2020-10-12 10:36:23]10.0.12.164 content: ... 30 common frames omitted [2020-10-12 10:36:23]10.0.12.164 content: Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60000, active 0, maxActive 20, creating 1, createElapseMillis 1360, createErrorCount 3737 [2020-10-12 10:36:23]10.0.12.164 content: at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82) ~[spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE] [2020-10-12 10:36:23]10.0.12.164 content: at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80) ~[mybatis-spring-2.0.4.jar!/:2.0.4] [2020-10-12 10:36:23]10.0.12.164 content: at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67) ~[mybatis-spring-2.0.4.jar!/:2.0.4] [2020-10-12 10:36:23]10.0.12.164 content: at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336) ~[mybatis-3.5.4.jar!/:3.5.4] [2020-10-12 10:36:23]10.0.12.164 content: at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86) ~[mybatis-3.5.4.jar!/:3.5.4] [2020-10-12 10:36:23]10.0.12.164 content: at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) ~[mybatis-3.5.4.jar!/:3.5.4] [2020-10-12 10:36:23]10.0.12.164 content: at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) ~[mybatis-3.5.4.jar!/:3.5.4] [2020-10-12 10:36:23]10.0.12.164 content: at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[mybatis-3.5.4.jar!/:3.5.4] [2020-10-12 10:36:23]10.0.12.164 content: at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) ~[mybatis-3.5.4.jar!/:3.5.4] [2020-10-12 10:36:23]10.0.12.164 content: at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:108) ~[pagehelper-5.1.11.jar!/:na] [2020-10-12 10:36:23]10.0.12.164 content: at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.4.jar!/:3.5.4] [2020-10-12 10:36:23]10.0.12.164 content: at com.sun.proxy.$Proxy135.query(Unknown Source) ~[na:na] [2020-10-12 10:36:23]10.0.12.164 content: at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ~[mybatis-3.5.4.jar!/:3.5.4] [2020-10-12 10:36:23]10.0.12.164 content: ... 35 common frames omitted [2020-10-12 10:36:23]10.0.12.164 content: Caused by: com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 60000, active 0, maxActive 20, creating 1, createElapseMillis 1360, createErrorCount 3737 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1732) ~[druid-1.1.23.jar!/:1.1.23] [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1404) ~[druid-1.1.23.jar!/:1.1.23] [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:5059) ~[druid-1.1.23.jar!/:1.1.23] [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterAdapter.dataSource_getConnection(FilterAdapter.java:2756) ~[druid-1.1.23.jar!/:1.1.23] [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:5055) ~[druid-1.1.23.jar!/:1.1.23] [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterAdapter.dataSource_getConnection(FilterAdapter.java:2756) ~[druid-1.1.23.jar!/:1.1.23] [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:5055) ~[druid-1.1.23.jar!/:1.1.23] -64 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:680) ~[druid-1.1.23.jar!/:1.1.23] -63 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:5055) ~[druid-1.1.23.jar!/:1.1.23] -62 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1382) ~[druid-1.1.23.jar!/:1.1.23] -61 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1374) ~[druid-1.1.23.jar!/:1.1.23] -60 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:98) ~[druid-1.1.23.jar!/:1.1.23] -59 [2020-10-12 10:36:23]10.0.12.164 content: at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:158) ~[spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE] -58 [2020-10-12 10:36:23]10.0.12.164 content: at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:116) ~[spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE] -57 [2020-10-12 10:36:23]10.0.12.164 content: at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79) ~[spring-jdbc-5.2.8.RELEASE.jar!/:5.2.8.RELEASE] -56 [2020-10-12 10:36:23]10.0.12.164 content: ... 47 common frames omitted -55 [2020-10-12 10:36:23]10.0.12.164 content: Caused by: java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. -54 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -53 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -52 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -51 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -50 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -49 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:906) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -48 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:831) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -47 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -46 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -45 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -44 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156) ~[druid-1.1.23.jar!/:1.1.23] -43 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:787) ~[druid-1.1.23.jar!/:1.1.23] -42 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) ~[druid-1.1.23.jar!/:1.1.23] -41 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:787) ~[druid-1.1.23.jar!/:1.1.23] -40 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) ~[druid-1.1.23.jar!/:1.1.23] -39 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218) ~[druid-1.1.23.jar!/:1.1.23] -38 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) ~[druid-1.1.23.jar!/:1.1.23] -37 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1646) ~[druid-1.1.23.jar!/:1.1.23] -36 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1710) ~[druid-1.1.23.jar!/:1.1.23] -35 [2020-10-12 10:36:23]10.0.12.164 content: at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2774) ~[druid-1.1.23.jar!/:1.1.23] -34 [2020-10-12 10:36:23]10.0.12.164 content: Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure -33 [2020-10-12 10:36:23]10.0.12.164 content: -32 [2020-10-12 10:36:23]10.0.12.164 content: The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. -31 [2020-10-12 10:36:23]10.0.12.164 content: at sun.reflect.GeneratedConstructorAccessor119.newInstance(Unknown Source) ~[na:na] -30 [2020-10-12 10:36:23]10.0.12.164 content: at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_144] -29 [2020-10-12 10:36:23]10.0.12.164 content: at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_144] -28 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -27 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -26 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -25 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -24 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:334) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -23 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:164) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -22 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1342) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -21 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.NativeSession.connect(NativeSession.java:157) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -20 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:850) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -19 [2020-10-12 10:36:23]10.0.12.164 content: ... 14 common frames omitted -18 [2020-10-12 10:36:23]10.0.12.164 content: Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateExpiredException: NotAfter: Mon Oct 12 01:12:03 CST 2020 -17 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) ~[na:1.8.0_144] -16 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959) ~[na:1.8.0_144] -15 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) ~[na:1.8.0_144] -14 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) ~[na:1.8.0_144] -13 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1514) ~[na:1.8.0_144] -12 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) ~[na:1.8.0_144] -11 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026) ~[na:1.8.0_144] -10 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.Handshaker.process_record(Handshaker.java:961) ~[na:1.8.0_144] -9 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072) ~[na:1.8.0_144] -8 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385) ~[na:1.8.0_144] -7 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413) ~[na:1.8.0_144] -6 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397) ~[na:1.8.0_144] -5 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:336) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -4 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -3 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -2 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:325) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] -1 [2020-10-12 10:36:23]10.0.12.164 content: ... 18 common frames omitted 0 [2020-10-12 10:36:23]10.0.12.164 content: Caused by: java.security.cert.CertificateExpiredException: NotAfter: Mon Oct 12 01:12:03 CST 2020 +1 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.x509.CertificateValidity.valid(CertificateValidity.java:274) ~[na:1.8.0_144] +2 [2020-10-12 10:36:23]10.0.12.164content: at sun.security.x509.X509CertImpl.checkValidity(X509CertImpl.java:629) ~[na:1.8.0_144] +3 [2020-10-12 10:36:23]10.0.12.164content: at sun.security.x509.X509CertImpl.checkValidity(X509CertImpl.java:602) ~[na:1.8.0_144] +4 [2020-10-12 10:36:23]10.0.12.164 content: at com.mysql.cj.protocol.ExportControlled$X509TrustManagerWrapper.checkServerTrusted(ExportControlled.java:383) ~[mysql-connector-java-8.0.21.jar!/:8.0.21] +5 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(SSLContextImpl.java:985) ~[na:1.8.0_144] +6 [2020-10-12 10:36:23]10.0.12.164 content: at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1496) ~[na:1.8.0_144] +7 [2020-10-12 10:36:23]10.0.12.164 content: ... 29 common frames omitted
在MySQL数据库中,有一个系统变量wait_timeout用于指定连接的最长等待时间。默认情况下,该值为8小时(即28800秒)。如果连接在这段时间内没有任何交互,则MySQL服务器会自动断开连接。
为了避免连接被自动断开,可以通过以下方式来延长wait_timeout的时间:
在MySQL服务器上修改全局配置文件my.cnf或my.ini,在[mysqld]节点下添加以下行:
wait_timeout = 86400
将wait_timeout设置为更大的值,以延长连接的最长等待时间。
在应用程序中,在建立连接之后发送一个“ping”命令,以保持与MySQL服务器的交互。例如,使用以下语句:
SHOW VARIABLES LIKE 'version_comment';
这个查询不会返回任何有用的信息,但它会向MySQL服务器发送一个请求并接收响应,从而保持连接的活跃状态。
需要注意的是,过长的wait_timeout值可能会导致连接池资源耗尽。因此,建议根据实际需求和环境进行适当的调整。
总之,在MySQL数据库中,连接的最长等待时间由系统变量wait_timeout控制,默认为8小时。可以通过修改wait_timeout变量或在应用程序中发送“ping”命令等方式来延长连接的生命周期。
wait_timeout = 86400表示将MySQL数据库中的wait_timeout参数设置为86400秒,即24小时。这意味着如果一个连接在24小时内没有任何交互,则MySQL服务器会自动断开该连接。
需要注意的是,过长的wait_timeout值可能会导致连接池资源耗尽。因此,建议根据实际需求和环境进行适当的调整。
一般情况下,如果应用程序中存在长时间空闲的连接,可以通过定期执行一些简单的查询操作或使用心跳机制来保持连接的活跃状态,并避免连接被自动断开。
总之,wait_timeout = 86400表示将MySQL数据库中的wait_timeout参数设置为24小时。建议根据实际需求和环境进行适当的调整。